import os
from dotenv import load_dotenv

# 加载环境变量
load_dotenv()

# 项目根目录
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_DIR = os.path.dirname(ROOT_DIR)

# 测试数据目录
TEST_DATA_DIR = os.path.join(PARENT_DIR, "test_data")

# 日志目录
LOG_DIR = os.path.join(PARENT_DIR, "logs")
if not os.path.exists(LOG_DIR):
    os.makedirs(LOG_DIR)

# 截图目录
SCREENSHOT_DIR = os.path.join(PARENT_DIR, "screenshots")
if not os.path.exists(SCREENSHOT_DIR):
    os.makedirs(SCREENSHOT_DIR)

# 测试报告目录
REPORT_DIR = os.path.join(PARENT_DIR, "reports")
if not os.path.exists(REPORT_DIR):
    os.makedirs(REPORT_DIR)

# 浏览器配置
BROWSER_CONFIG = {
    "browser": os.getenv("BROWSER", "chrome"),
    "headless": os.getenv("HEADLESS", "false").lower() == "true",
    "implicit_wait": int(os.getenv("IMPLICIT_WAIT", 10)),
    "explicit_wait": int(os.getenv("EXPLICIT_WAIT", 10)),
    "window_size": (1920, 1080)
}

# 应用配置
# APP_CONFIG = {
#     "base_url": os.getenv("BASE_URL", "https://example.com"),
#     "login_url": os.getenv("LOGIN_URL", "https://example.com/login")
# }

# 邮件配置
EMAIL_CONFIG = {
    "smtp_server": os.getenv("SMTP_SERVER", "smtp.example.com"),
    "smtp_port": int(os.getenv("SMTP_PORT", 465)),
    "smtp_ssl": os.getenv("SMTP_SSL", "true").lower() == "true",
    "sender": os.getenv("EMAIL_SENDER", "sender@example.com"),
    "password": os.getenv("EMAIL_PASSWORD", "password"),
    "receivers": os.getenv("EMAIL_RECEIVERS", "recipient@example.com").split(","),
    "subject": os.getenv("EMAIL_SUBJECT", "UI自动化测试报告")
}

# 数据库配置（如果需要）
DB_CONFIG = {
    "host": os.getenv("DB_HOST", "localhost"),
    "port": int(os.getenv("DB_PORT", 3306)),
    "user": os.getenv("DB_USER", "root"),
    "password": os.getenv("DB_PASSWORD", "password"),
    "database": os.getenv("DB_DATABASE", "test")
}

# print(os.getenv("DB_HOST", "localhost"))
BASE_URL = "https://u.zhimawork.com"
APPLY_URL = BASE_URL + "/web/register.php"
